package com.example.libraryapp.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.libraryapp.R;
import com.example.libraryapp.util.Constance;
import com.example.libraryapp.webview.WebviewActivity;

/**
 * 外链Fragment
 */
public class FourthFragment extends Fragment {

	private static Handler handler;
	private Context context;
	private ImageView ivGW;
	private ImageView ivJW;
	private ImageView ivTSG;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		init();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		if (container == null) {
			return null;
		}
		View view = inflater
				.inflate(R.layout.fourth_fragment, container, false);
		findViews(view);
		setListener();
		return view;
	}

	/**
	 * 初始化
	 */
	private void init() {
		// TODO Auto-generated method stub
		context = getActivity();

		handler = new Handler() {

			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				super.handleMessage(msg);
				switch (msg.what) {

				default:
					break;
				}
			}

		};
	}

	/**
	 * 找到控件
	 * 
	 * @param view
	 */
	private void findViews(View view) {
		ivGW = (ImageView) view.findViewById(R.id.iv_gw);
		ivJW = (ImageView) view.findViewById(R.id.iv_jw);
		ivTSG = (ImageView) view.findViewById(R.id.iv_tsg);
	}

	/**
	 * 设置监听
	 */
	private void setListener() {
		// 学校官网
		ivGW.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getActivity(), WebviewActivity.class);
				intent.putExtra("title", "学校官网");
				intent.putExtra("url", Constance.GW_URL);
				startActivity(intent);
			}
		});
		// 教务系统
		ivJW.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getActivity(), WebviewActivity.class);
				intent.putExtra("title", "教务系统");
				intent.putExtra("url", Constance.JW_URL);
				startActivity(intent);
			}
		});
		// 图书馆
		ivTSG.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getActivity(), WebviewActivity.class);
				intent.putExtra("title", "图书馆");
				intent.putExtra("url", Constance.TSG_URL);
				startActivity(intent);
			}
		});
	}
}
